﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Web;
using Sok.Munkae.ApplicationServices.Membership;
using Sok.Munkae.Core;

namespace Sok.Munkae.Web.FormsAuthentication
{

    public class ThreadUserContext : IUserContext
    {
        public void SetPrincipal(IPrincipal principal)
        {
            Thread.CurrentPrincipal = principal;
        }

        public IPrincipal GetPrincipal()
        {
            return Thread.CurrentPrincipal;
        }

        public void SetUser(User principal)
        {
            Thread.CurrentPrincipal = principal;
        }

        public User GetUser()
        {
            var fn = Thread.CurrentPrincipal.GetType().FullName;
            var p = Thread.CurrentPrincipal;
            return (Thread.CurrentPrincipal as User);
        }
    }

    public class HttpUserContext : IUserContext
    {
        public void SetPrincipal(IPrincipal principal)
        {
            HttpContext.Current.User = principal;
        }
        
        public IPrincipal GetPrincipal()
        {
            return HttpContext.Current.User;
        }

        public void SetUser(User user)
        {
            HttpContext.Current.User = user;
        }

        public User GetUser()
        {
            return (User) HttpContext.Current.User;
        }
    }
}
